﻿using BellAssistant.Model.Tables;
using CDataContext;

namespace BellAssistant.WebAPI.Context
{
    public class BellDataContext : DataContext
    {
        private static BellDataContext dc;
        public static BellDataContext GetInstance()
        {
            if (dc == null)
            {
                dc = new BellDataContext(CDataContext.EProvider.SqlServer, Properties.Settings.Default.Connstr);
                string filePath = Properties.Settings.Default.LogFilePath;
                dc.log = new EAF.Log.Log(filePath, EAF.Log.LogType.Daily);
                dc.isDebug = true;
                dc.log.Write("-----------------------UpdateSQL----------------------");
                //自动更新数据库表
                dc.CheckAllSchema();
            }
            return dc;
        }
        public BellDataContext()
        {
            UpdateSQL();
        }
        public BellDataContext(CDataContext.EProvider provider, string connString) : base(provider, connString)
        {
            UpdateSQL();
        }

        private void UpdateSQL()
        {
            #region 存储过程
            ///2017年3月14日 14:57:52增加存储过程，解决一点批量领卡的性能问题
            //list_Update_Sql.Add(new VersionSql(1, @"Create proc sp_UpdateSSCNotGotRecord
            //                                         @RecordID int,
            //                                         @ArchiveCode nvarchar(10),
            //                                         @Remarks nvarchar(100)
            //                                     as
            //                                         begin
            //                                       update SSCNotGotRecord set ArchiveCode=@ArchiveCode,Remarks=@Remarks where RecordID=@RecordID
            //                                         end"));
            #endregion
        }

        #region 数据表

        public CTable<UserInfo> UserInfo = new CTable<UserInfo>();

        public CTable<Goods> Goods = new CTable<Goods>();

        public CTable<ProductCategory> ProductCategory = new CTable<ProductCategory>();

        public CTable<Brand> Brand = new CTable<Brand>();

        public CTable<ExpressType> ExpressType = new CTable<ExpressType>();

        public CTable<PromotionType> PromotionType = new CTable<PromotionType>();

        public CTable<Coupon> Coupon = new CTable<Coupon>();

        #endregion
    }
}